<?php
include_once 'inc.php';
switch ($modaction) {
	/***********************************************商品部分******************************************************/

	case 'list':
		$sql='select a.id as aid,a.name as aname,a.is_close as is_close,a.groupprice as aprice,a.costprice as cost_price,a.salenum as salenum,a.smallnum as small_num,a.bignum as big_num,a.overtime as over_time,b.name as bname from sn_group_goods as a
		      left join sn_group_menchant as b 
		      on a.merchant_id = b.id where a.isdel ="N" and b.isdel="N" ';
		$group_goods_list=$db->getlist($sql);
		require_once 'them/admin_list.htm';
		break;
	case 'add':
		$fm_is_close=true_false_select('fm_is_close');
		$fm_is_index_show=true_false_select('fm_is_index_show');
		//非smarty方式初始化所有需要的编辑器
	//	$iexplain=create_html_editor($editor,'fm_explain','',false);
		$name_dic=create_html_editor($editor,'fm_name_dic','',false);
		$description=create_html_editor($editor,'fm_description','',false);
		$other_dic=create_html_editor($editor,'fm_other_dic','',false);
		$them_says=create_html_editor($editor,'fm_them_says','',false);
		$we_syas=create_html_editor($editor,'fm_we_syas','',false);

		//获取商家下拉
		$menchantslist=getmenchantslist();
		$citylist=getcitylist();
		$imgbox=create_uploadfile('fm_bigimg','do/ajax/upimg.php','','fm_smallimg');//创建图片上传文本框

		require_once 'them/admin_info.htm';
		break;
	case 'edit':
		$sql='select * from sn_group_goods where id='.$_REQUEST['id'];
		$res=$db->getrow($sql);

		$fm_is_close=true_false_select('fm_is_close',$res['is_close']);
		$fm_is_index_show=true_false_select('fm_is_index_show',$res['is_index_show']);
		//非smarty方式初始化所有需要的编辑器
	//	$iexplain=create_html_editor($editor,'fm_explain',$res['iexplain'],false);
		$name_dic=create_html_editor($editor,'fm_name_dic',$res['name_dic'],false);
		$description=create_html_editor($editor,'fm_description',$res['description'],false);
		$other_dic=create_html_editor($editor,'fm_other_dic',$res['other_dic'],false);
		$them_says=create_html_editor($editor,'fm_them_says',$res['them_says'],false);
		$we_syas=create_html_editor($editor,'fm_we_syas',$res['we_syas'],false);

		//获取商家下拉
		$menchantslist=getmenchantslist($res['merchant_id']);
		$citylist=getcitylist($res['city']);
		$imgbox=create_uploadfile('fm_bigimg','do/ajax/upimg.php',$res['bigimg'],'fm_smallimg',$res['smallimg']);//创建图片上传文本框

		require_once 'them/admin_info.htm';
		//*/
		break;
	case 'insert':
		/*
		 echo $_REQUEST['fm_description'];
		 echo $_REQUEST['fm_explain'];
		 echo $_REQUEST['fm_name_dic'];
		 //*/

		if($_REQUEST['fm_name']!==''){
			$post=array(
			name=>$_REQUEST['fm_name'],
			merchant_id=>$_REQUEST['fm_merchant_id'],
			city=>$_REQUEST['fm_city'],
			smallnum=>$_REQUEST['fm_smallnum'],
			bignum=>$_REQUEST['fm_bignum'],
			overtime=>$_REQUEST['fm_overtime'],
			couponovertime=>$_REQUEST['fm_couponovertime'],
			costprice=>$_REQUEST['fm_costprice'],
			groupprice=>$_REQUEST['fm_groupprice'],
			bigimg=>$_REQUEST['fm_bigimg'],
			smallimg=>$_REQUEST['fm_smallimg'],
		//	iexplain=>trim($_REQUEST['fm_explain']),
			name_dic=>$_REQUEST['fm_name_dic'],
			description=>$_REQUEST['fm_description'],
			other_dic=>$_REQUEST['fm_other_dic'],
			them_says=>$_REQUEST['fm_them_says'],
			we_syas=>$_REQUEST['fm_we_syas'],
			is_close=>$_REQUEST['fm_is_close'],
			is_index_show=>$_REQUEST['fm_is_index_show']
			);
			$res=$db->insert('sn_group_goods',$post);
			if($res==true){
				sys_msg('发布成功!',0);

			}
		}else{
			sys_msg('团购名称不能为空!',1);

		}
		//*/
		break;
	case 'update':

		if($_REQUEST['fm_name']!==""){

			if($_REQUEST['fm_id']=="" || $_REQUEST['fm_id']==null)
			{
				sys_msg('未指定团购无法修改！',1);
				exit();
			}else {
				$fm_id=$_REQUEST['fm_id'];
			}
			//修改更新数据
			$post=array(
			id=>$fm_id,//要更改的id

			name=>$_REQUEST['fm_name'],
			merchant_id=>$_REQUEST['fm_merchant_id'],
			city=>$_REQUEST['fm_city'],
			smallnum=>$_REQUEST['fm_smallnum'],
			bignum=>$_REQUEST['fm_bignum'],
			overtime=>$_REQUEST['fm_overtime'],
			couponovertime=>$_REQUEST['fm_couponovertime'],
			costprice=>$_REQUEST['fm_costprice'],
			groupprice=>$_REQUEST['fm_groupprice'],
			bigimg=>$_REQUEST['fm_bigimg'],
			smallimg=>$_REQUEST['fm_smallimg'],
		//	iexplain=>trim($_REQUEST['fm_explain']),
			name_dic=>$_REQUEST['fm_name_dic'],
			description=>$_REQUEST['fm_description'],
			other_dic=>$_REQUEST['fm_other_dic'],
			them_says=>$_REQUEST['fm_them_says'],
			we_syas=>$_REQUEST['fm_we_syas'],
			is_close=>$_REQUEST['fm_is_close'],
			is_index_show=>$_REQUEST['fm_is_index_show']
			);

			$res=$db->update('sn_group_goods',$post,id);
			if($res==true){
				sys_msg('修改成功!',0);
			}
		}else{
			sys_msg('团购名称不能为空!',1);
		}
		break;
	case 'delete':
		$sql='update sn_group_goods set isdel = "Y" where id='.$_REQUEST['id'];
		$res=$db->query($sql);
		if($res==true){
			sys_msg('删除成功!',0);
		}
		break;
	case 'close':
		$sql='update sn_group_goods set is_close = "Y" where id='.$_REQUEST['id'];
		$res=$db->query($sql);
		if($res==true){
			sys_msg('关闭成功!',0);
		}
		break;
	case 'open':
		$sql='update sn_group_goods set is_close = "N" where id='.$_REQUEST['id'];
		$res=$db->query($sql);
		if($res==true){
			sys_msg('开启成功!',0);
		}
		break;
		/***********************************************商家部分******************************************************/
	case 'mlist':
		$sql='SELECT a.id AS aid, a.name AS aname, a.tel AS atel, a.url AS aurl, a.mail AS amail, a.addr AS addr, a.isdel AS aisdel, COUNT( b.id ) AS countgoods
              FROM sn_group_menchant AS a
              LEFT JOIN sn_group_goods AS b ON b.merchant_id = a.id
              WHERE a.isdel = "N"
              GROUP BY a.id';
		$group_merchant_list=$db->getlist($sql);
		require_once 'them/admin_merchant_list.htm';
		break;
	case 'madd':
		require_once 'them/admin_merchant_info.htm';
		break;
	case 'medit':
		$sql='select * from sn_group_menchant where id='.$_REQUEST['id'];
		$res=$db->getrow($sql);
		require_once 'them/admin_merchant_info.htm';
		break;
	case 'minsert':
		if($_REQUEST['fm_name']!==''){
			$post=array(
			name=>$_REQUEST['fm_name'],
			tel=>$_REQUEST['fm_tel'],
			url=>$_REQUEST['fm_url'],
			mail=>$_REQUEST['fm_mail'],
			addr=>$_REQUEST['fm_addr'],
			password=>$_REQUEST['fm_password']
			);
			$res=$db->insert('sn_group_menchant',$post);
			if($res==true){
				sys_msg('发布成功!',0);
			}
		}else{
			sys_msg('商家名称不能为空!',1);
		}
		break;
	case 'mupdate':
		if($_REQUEST['fm_name']!==''){
			if($_REQUEST['fm_id']=="" || $_REQUEST['fm_id']==null)
			{
				sys_msg('未指定商家无法修改！',1);
				exit();
			}else {
				$fm_id=$_REQUEST['fm_id'];
			}
			$post=array(
			id=>$fm_id,
			name=>$_REQUEST['fm_name'],
			tel=>$_REQUEST['fm_tel'],
			url=>$_REQUEST['fm_url'],
			mail=>$_REQUEST['fm_mail'],
			addr=>$_REQUEST['fm_addr'],
			password=>$_REQUEST['fm_password']
			);
			$res=$db->update('sn_group_menchant',$post,id);
			if($res==true){
				sys_msg('修改成功!',0);
			}
		}else{
			sys_msg('商家名称不能为空!',1);
		}
		break;
	case 'mdel':
		$sql='update sn_group_menchant set isdel = "Y" where id='.$_REQUEST['id'];
		$res=$db->query($sql);
		if($res==true){
			sys_msg('删除成功!',0);
		}
		break;
	default:
		//主控制面板初始化
		require_once 'them/admin.htm';
		break;
}
?>